package scenetracer.core;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import scenetracer.core.light.Light;
import scenetracer.core.parser.SCParser;
import scenetracer.core.shader.Shader;

public class Scene {
	
	private Map<String, Shader> shaders;
	private List<Primitive> primitiveList = new ArrayList<Primitive>();
	private List<Light> lightList = new ArrayList<Light>();
	private Camera cam;
	private int width, height, AntialiasingMinValue, AntialiasingMaxValue, samples = 1;
	private double factorOfContrast = 0.1;
	private String filter = null;
	private boolean jitter = false;
	private int penumbra=0;

	// CONSTRUCTOR
	public Scene(){
	}
		
	public final boolean parse(String filename, int penumbra) {
		SceneParser parser; 
		
		if (filename == null)
	            return false;
        if (filename.endsWith(".sc"))
            parser = new SCParser(penumbra);
        else {
            System.out.println("File type not supported");
            return false;
        }
        return parser.parse(filename, this);	
	}
	
	public Camera getCamera() {
		return cam;
	}

	public void setCamera(Camera cam) {
		this.cam = cam;
	}

	public int getWidth() {
		return width;
	}
	
	public void setWidth(int width) {
		this.width = width;
	}
	
	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
	
	public void setAntialiasingMinValue(int aamin) {
		this.AntialiasingMinValue = aamin;
	}

	public int getAntialiasingMaxValue() {
		return AntialiasingMaxValue;
	}

	public void setAntialiasingMaxValue(int aamax) {
		this.AntialiasingMaxValue = aamax;
	}

	public int getSamples() {
		return samples;
	}

	public int getAntialiasingMinValue() {
		return AntialiasingMinValue;
	}

	public void setSamples(int samples) {
		this.samples = samples;
	}

	public double getContrast() {
		return factorOfContrast;
	}

	public void setContrast(double contrast) {
		this.factorOfContrast = contrast;
	}

	public String getFilter() {
		return filter;
	}

	public void setFilter(String filter) {
		this.filter = filter;
	}

	public boolean isJitter() {
		return jitter;
	}

	public void setJitter(boolean jitter) {
		this.jitter = jitter;
	}

	public void addPrimitive(Primitive primitive) {
		if (this.primitiveList != null) {
			this.primitiveList.add(primitive);
		}
	}

	/*
	public void addPrimitives(List<Triangle_aux> primitives) {
		if (this.primitiveList != null) {
			this.primitiveList.addAll(primitives);
		}
	}
	*/
	
	public void addLight(Light light) {
		this.primitiveList.add(light);
		this.lightList.add(light);		
	}
	
	public Map<String, Shader> getShaders() {
		return shaders;
	}

	public void setShaders(Map<String, Shader> shaders) {
		this.shaders = shaders;
	}
	
	public void setPrimitives(List<Primitive> primitives) {
		this.primitiveList = primitives;
	}

	public List<Primitive> getPrimitives() {
		return primitiveList;
	}
	
	public List<Light> getLights(){
		return lightList;
	}
	
	
/*	
	public BoundingBox getWorldBounds() {
		BoundingBox bounds = new BoundingBox();
		
		for (int i = 0; i < primitiveList.size(); i++) {
			bounds.include(primitiveList.get(i).getBounds(null));
		}
		return bounds;
	}
	
	public float getBound(int primitiveNumber, int boundNumber) {
		return primitiveList.get(primitiveNumber).getBounds(null).getBound(boundNumber);
	}
*/
	/*
	public void addPrimitives(Triangle_aux[] meshTriangles) {
		for(int i = 0; i< meshTriangles.length ; i++)
			primitiveList.add(meshTriangles[i]);
		
	}
	*/

	public void setPenumbra(int penumbra) {
		this.penumbra = penumbra;
	}

	public int getPenumbra() {
		return penumbra;
	}
	

	
}
